console.log(axios);

function async(generator) {
  let iterator = generator(); // 获取迭代器
  function handle(iteratorResult) {
    if (iteratorResult.done) return;
    const iteratorValue = iteratorResult.value;
    if (iteratorValue instanceof Promise) {
      iteratorValue
        .then((res) => {
          handle(iterator.next(res)); // 已经获取到第一次请求的值了 进行的是下一次迭代
        })
        .catch((err) => {
          iterator.throw(err); //抛出错误
        });
    }
    // { value:'xxx',done:true}
  }
  try {
    handle(iterator.next());
  } catch (error) {
    iterator.throw(error);
  }
}

async(function* () {
  try {
    let res1 = yield axios.get('http://localhost:666/base');
    console.log('res1', res1.data.name);
    let res2 = yield axios.get(
      'http://localhost:666/about?user=' + res1.data.name
    );
    console.log('res2', res2);
    let res3 = yield axios.get('http://localhost:666/detail?msg=' + res2.data);
    console.log('res3', res3);
  } catch (error) {
    console.log('has some error');
  }
});

// async function getMsg(params) {
//   let res = await axios.get('http://localhost:666');
//   console.log(res);
// }

// getMsg();
